//
//  HMPeopleCenterViewController.m
//  HMSupplier
//
//  Created by haohao on 2017/7/3.
//  Copyright © 2017年 haohao. All rights reserved.
//

#import "HMPeopleCenterViewController.h"
#import "HMPeopleListTableViewCell.h"
#import "HMBillViewController.h"
#import "HMBillingRecordController.h"
#import "HMLoginController.h"
#import "HMChangePasswordController.h"
#import "BaseNaviViewController.h"

@interface HMPeopleCenterViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *myTableView;

@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation HMPeopleCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setSubView];
    // Do any additional setup after loading the view from its nib.
}

- (void)setSubView {
    _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KWidthSCREEN, KHeightSCREEN) style:UITableViewStyleGrouped];
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    _myTableView.separatorColor = [UIColor clearColor];
    [self.view addSubview:_myTableView];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HMPeopleListTableViewCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"HMPeopleListTableViewCell" owner:self options:nil] firstObject];
    cell.index = indexPath;
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        HMBillingRecordController *vc = [[HMBillingRecordController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.section == 1) {
        HMChangePasswordController * vc = [[HMChangePasswordController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
//    if (indexPath.section == 2) {
//        
//    }
    if (indexPath.section == 2) {
        
        [MGAccountTool removeAccount];
        
        CATransition * anim = [CATransition animation];
        anim.type = @"kCATransitionMoveIn";
        anim.duration = 0.5;
        [[UIApplication sharedApplication].keyWindow.layer addAnimation:anim forKey:nil];
        
        HMLoginController * vc = [[HMLoginController alloc] init];
        BaseNaviViewController * nav = [[BaseNaviViewController alloc] initWithRootViewController:vc];
        [UIApplication sharedApplication].keyWindow.rootViewController = nav;
        
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 45;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001;
}

@end
